using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FrameWorkSong;

public class WallBulidControl : Singleton<WallBulidControl>
{
    public Wall CurrentWall; 
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (CurrentWall)
            {
                Vector3 rayPoint = MouseRayPoint();
                Debug.Log(rayPoint);
                if (rayPoint!=Vector3.zero)
                {
                    CurrentWall.AddKeyPoint(rayPoint);
                    CurrentWall.Create();
                    CurrentWall.BeginCreate = true;
                }
            
            }
        }
        //if (CurrentWall&&CurrentWall.BeginCreate)
        //{
        //    CurrentWall.MovePoints = MouseRayPoint();
        //    CurrentWall.Create();
        //}
        if (Input.GetMouseButtonDown(1))
        {
            CurrentWall.CreateHigh();
            CurrentWall.BeginCreate = false;
            CurrentWall = null;
        }
    }
    Vector3 MouseRayPoint()
    {
        Ray ray=Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit raycastHit;
        if (Physics.Raycast(ray, out raycastHit))
        {
            return raycastHit.point;
        }
        else
        {
            return Vector3.zero;
        }
    }

    public override void OnBeforeDestroy()
    {
        
    }
}
